package org.scboy.rbac.service.imp;

import java.util.Date;
import java.util.List;

import org.scboy.coobi.sql.factory.EntityFactory;
import org.scboy.rbac.dao.RbacOrgTypeJoinDao;
import org.scboy.rbac.service.OrgTypeJoinService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hutool.core.lang.UUID;


@Service("rbac_orgTypeJoinServiceImp")
public class OrgTypeJoinServiceImp implements OrgTypeJoinService {

	@Autowired
	EntityFactory factory;
	
	@Override
	public boolean add(String otId, String jotId) {
		RbacOrgTypeJoinDao dao=factory.getDao(RbacOrgTypeJoinDao.class);
		long count = dao.count(Model.create().add("otId", otId).add("jotId", jotId));
		if (count > 0) {
			return false;
		}
		Model model = Model.create()
				.add("id", UUID.randomUUID().toString())
				.add("otId", otId)
				.add("jotId", jotId)
				.add("addTime", new Date())
				.add("edit", new Date());
		
		int result = dao.insert(model);
		if (result > 0) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean delete(String id) {
		RbacOrgTypeJoinDao dao=factory.getDao(RbacOrgTypeJoinDao.class);
		int rseult = dao.delete(Model.create().add("id", id));
		if (rseult > 0) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public Page page(Model model) {
		RbacOrgTypeJoinDao dao=factory.getDao(RbacOrgTypeJoinDao.class);
		return dao.queryPage(model);
		
	}

	@Override
	public List<Model> get(String id) {
		RbacOrgTypeJoinDao dao=factory.getDao(RbacOrgTypeJoinDao.class);
		return dao.select(Model.create().add("otId",id));
	}

}
